package twoOutOfThree;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Solution {
    public List<Integer> twoOutOfThree(int[] nums1, int[] nums2, int[] nums3) {
        Set<Integer> set1 = new HashSet<>();
        Set<Integer> set2 = new HashSet<>();
        Set<Integer> set3 = new HashSet<>();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < nums1.length; i++) {
            set1.add(nums1[i]);
        }
        for (int i = 0; i < nums2.length; i++) {
            set2.add(nums2[i]);
        }
        for (int i = 0; i < nums3.length; i++) {
            set3.add(nums3[i]);
        }
        int[] marks = new int[101];
        for (int v: set1) {
            marks[v]++;
        }
        for (int v: set2) {
            marks[v]++;
        }
        for (int v: set3) {
            marks[v]++;
        }
        for (int i = 0; i <= 100; i++) {
            if(marks[i] >=2){
                list.add(i);
            }
        }
        return list;
    }
}
